<template>
	<view>
		<u-swiper :indicator="true" indicatorMode="number" previousMargin="100" nextMargin="100" :circular="true" keyName="path" indicator-pos="bottomRight" :list="list" :autoplay="false" :current="current"
			@change="change" height="1160"></u-swiper>
		<view class="poster-bottom">
			<!-- <view class="poster-bottom-item" @click="saveFile()">
				<u-icon slot="icon" size="88" custom-prefix='gewu' name="baocun"></u-icon>
				<text class="poster-bottom-title">保存到相册</text>
			</view> -->
			<view style="display: flex;flex-direction: row; justify-content: space-around; width: 400rpx;margin-top: 40rpx;">
				<button @click="saveFile()" :plain="true" style="display: flex;flex-direction: column;justify-content: center;align-items: center; border: none;">
					<u-image width="100rpx" height="100rpx" mode="widthFix" src="https://img.koalalf.com/share/haibao.png"></u-image>
					<text style="font-size: 24rpx; color: #333;">保存海报</text>
				</button>
				<!-- <button :plain="true" style="display: flex;flex-direction: column;justify-content: center;align-items: center; border: none;" open-type="share">
					<u-image width="100rpx" mode="widthFix" src="https://img.koalalf.com/share/xiaochengxu.png"></u-image>
					<text style="margin-top: -24rpx;font-size: 24rpx; color: #333;">分享小程序</text>
				</button> -->
			</view>
			<!-- <view class="poster-bottom-item">
				<u-icon slot="icon" size="88" custom-prefix='gewu' name="weixin"></u-icon>
				<text class="poster-bottom-title">分享给好友</text>
			</view>
			<view class="poster-bottom-item">
				<u-icon slot="icon" size="88" custom-prefix='gewu' name="weixinpengyouquan"></u-icon>
				<text class="poster-bottom-title">分享到朋友圈</text>
			</view> -->
		</view>

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {poster} from "@/common/http.api.js"
	export default {
		data() {
			return {
				list: [],
				current: 0
			}
		},
		onLoad() {
			uni.showLoading({
				title: '正在获取推广海报'
			})
			let that = this;
			poster({}).then(res => {
				uni.hideLoading()
				console.log(res)
				that.list = res
			})
<<<<<<< HEAD
		},
		methods: {
			change(index) {
				this.current = index
			},
			saveFile() {
=======
		},
		methods: {
			change(index) {
				console.log(index)
				this.current = index.current
			},
			saveFile() {
>>>>>>> yihuishenghuo
				let that = this;
				uni.showLoading({
					title: '正在保存'
				})
				console.log(that.list[that.current].path)
				uni.downloadFile({
				    url: that.list[that.current].path,
				    success: (res) => {
				        if (res.statusCode === 200) {
				            uni.saveImageToPhotosAlbum({
				            	filePath: res.tempFilePath,
				            	success: function(res) {
				            		that.$refs.uToast.show({
										message:'保存成功',
				            			type: 'success',
				            		})
									
									uni.hideLoading()
				            	},
				            	fail: function(error) {
				            		that.$refs.uToast.show({
				            			message: '保存失败' + error.errMsg,
				            			type: 'error',
				            		})
									
									uni.hideLoading()
				            	}
				            });
				        }
				    }, fail: function(err){
						uni.hideLoading()
					}
				});
				
				// uni.requestSubscribeMessage({
				// 	tmplIds: ['pU54TKTQvbFU6Vt-YaQTrliA7sWm_8XTUDD0C1dv9rc'],
				// 	success(res) {
				// 		console.log(res)
				// 	}
				// })
				
				
			},
			
			onShareAppMessage(res) {
				let title = "测试测试"
				if (res.from === 'button') { // 来自页面内分享按钮
					return {
						title: title,
						path: '/pages/index/index?share_key=' + this.share_key,
						imageUrl: ''
					}
				}
				return {
					title: title,
					path: '/pages/index/index?share_key=' + this.share_key,
					imageUrl: ''
				}
			},
			
		}
	}
</script>

<style>
	body {
		background-color: #f5f5f5;
	}

	.poster-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		padding: 40rpx 0;
		position: fixed;
		bottom: 0;
		background-color: rgba(255,255,255, 0.8);
		width: 100%;
		/* padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom); */
	}

	.poster-bottom-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.poster-bottom-title {
		margin-top: 20rpx;

	}
</style>
